package com.example.scaffold_demo.http;


import android.content.Context;

import com.example.httplibrary.exception.ExceptionHandle;
import com.example.httplibrary.mvp.BaseView;
import com.example.httplibrary.rx.subscriber.ErrorHandlerSubscriber;

import io.reactivex.disposables.Disposable;

public abstract class ProgressSubcriber<T> extends ErrorHandlerSubscriber<T> {


    private BaseView mView;


    public ProgressSubcriber(Context context, BaseView view) {
        super(context);
        this.mView = view;

    }


    public boolean isShowProgress() {
        return true;
    }


    @Override
    public void onSubscribe(Disposable d) {
        if (isShowProgress()) {
            mView.showLoading();
        }
    }

    @Override
    public void onComplete() {

        mView.dismissLoading();
    }

    @Override
    public void onError(Throwable e) {
        e.printStackTrace();
        ExceptionHandle.ResponeThrowable baseException = mErrorHandler.handleException(e);

        mView.showError(baseException.getMessage());

    }

}
